﻿var CurrentType=0;

Ext.onReady(function () {
    PageSafe();

    var adstore = new Ext.data.JsonStore({
        url: Ext.getClassUrl('Advertisement.AdvertisementView', 'GetsearchAdvertisement'),
        root: 'ResponseObject',
        fields: ['PID', 'GName', 'GUrl', 'GRemark', 'Creater', 'Period', 'NTime', 'SurplusTime', 'GT', 'ChargeUser', 'ChargeUser.UserName', 'TransfS'],
        listeners: {
            beforeload: function (st, op) {
                var re = new JsonRequest();
                re.category = CATEGORY.READONLY;
                re.params.info = {
                    AdName: Ext.getCmp("SearchName").getValue(),
                    SearchType: CurrentType
                };
                st.baseParams = re;
                st.proxy.conn.jsonData = re;
            }
        }
    });
    var adsm = new Ext.grid.CheckboxSelectionModel({
        singleSelect: true
    });
    function NumFormat(s, m) {
        m.css = 'RedNum';
        return s;
    }
    var adgrid = new Ext.grid.GridPanel({
        bodyStyle: 'padding:2px',
        border: false,
        split: true,
        height: 500,
        sm: adsm,
        loadMask: true, //加载
        columns: [
       adsm,
       { id: 'GName', header: '广告名称', width: 130, dataIndex: 'GName', sortable: true },
       { id: 'GUrl', header: '广告路径', width: 200, dataIndex: 'GUrl', sortable: true },
       { id: 'ChargeUser.UserName', header: '发布人', width: 100, dataIndex: 'ChargeUser.UserName', sortable: true },
       { id: 'GRemark', header: '备注', width: 260, dataIndex: 'GRemark', sortable: true },
       { id: 'Period', header: '有效日期(天)', width: 100, dataIndex: 'Period', sortable: true },
       { id: 'GT', header: '来源', width: 100, dataIndex: 'GT', sortable: true },
        { id: 'TransfS', header: '状态', width: 100, dataIndex: 'TransfS', sortable: true },
       { id: 'SurplusTime', header: '剩余日期(天)', width: 100, dataIndex: 'SurplusTime', sortable: true, renderer: NumFormat },
       { id: 'NTime', header: '日期', width: 100, dataIndex: 'NTime', sortable: true }
   ],
        store: adstore
    });


    var panelwin = new Ext.Viewport({
        layout: 'border',
        items: [{
            region: 'center',
            title: '广告查看',
            tbar: ['名称查询：', { xtype: 'textfield', width: 100, id: 'SearchName', name: 'SearchName' }, { text: '查询', iconCls: 'search-icon', handler: function () {
                adstore.load();
            }
            }, { text: '查询全部', iconCls: 'allsearch-icon', handler: function () {
                CurrentType = 9;
            }
        }, { text: '查询通过审核', iconCls: 'passsearch-icon', handler: function () {
            CurrentType = 1;
        }
    }, { text: '查询正在审核', iconCls: 'passingsearch-icon', handler: function () {
        CurrentType = 2;
    }
}, { text: '查询未审核', iconCls: 'secretsearch-icon', handler: function () {
    CurrentType = 0;
} 
}],
            items: adgrid
        }],
        listeners: {
            render: function () {
                adstore.load();
            }
        }
    });
});